'''
Author: zhuyuejiang
Date: 2021-03-18 16:19:48
LastEditTime: 2021-03-19 17:15:56
Description: file context description
'''
from yacs.config import CfgNode as CN

def default_config():
    cfg = CN()
    #algorithms
    cfg.name = 'algorithms'

    print("default configing--------")
    # model
    cfg.model = CN()
    cfg.model.name = 'baseline'
    cfg.model.device = 'cuda'
    cfg.model.gpu_devices ='0'
    cfg.model.pretrained = True # automatically load pretrained model weights if available
    cfg.model.load_weights = ''# path to model weights
    cfg.model.resume = '' #path to checkpoint for resume training
    cfg.model.freeze_layers = []

    # backbone
    cfg.model.base = CN()
    cfg.model.base.name = 'resnet50'
    cfg.model.base.last_stride = 1

    # If use ImageNet pretrain model
    cfg.model.base.pretrain = False

    # loss
    cfg.model.loss = CN()
    cfg.model.loss.name = ("CrossEntropyLoss",)
    # Cross Entropy Loss options
    cfg.model.loss.ce = CN()
    cfg.model.loss.ce.epsilon = 0.1 # use label smoothing regularizer, 0 means no label smooth
    cfg.model.loss.ce.weight = 1.0
    # Triplet Loss options
    cfg.model.loss.triplet = CN()
    cfg.model.loss.triplet.margin = 0.3 # distance margin
    cfg.model.loss.triplet.weight = 1. # weight to balance hard triplet loss
    cfg.model.loss.triplet.hard_mining = False


    # data
    cfg.data = CN()
    cfg.data.root = 'reid-data'
    cfg.data.sources = 'market1501'
    cfg.data.targets = 'market1501'
    cfg.data.workers = 4 # number of data loading workers
    cfg.data.split_id = 0 # split index
    cfg.data.height = 256 # image height
    cfg.data.width = 128 # image width
    cfg.data.combineall = False # combine train, query and gallery for training
    cfg.data.transforms = ['random_flip', 'random_erase', 'random_crop'] # data augmentation
    cfg.data.padding = 0 # transform padding
    # random erasing
    cfg.data.rea = CN()
    cfg.data.rea.prob = 0.5
    cfg.data.rea.mean = [0.596, 0.558, 0.497]
    # Random Patch
    cfg.data.rpt = CN()
    cfg.data.rpt.prob = 0.5

    cfg.data.norm_mean = [0.485, 0.456, 0.406] # default is imagenet mean
    cfg.data.norm_std = [0.229, 0.224, 0.225] # default is imagenet std
    cfg.data.save_dir = 'log' # path to save log
    

    
    # sampler
    cfg.sampler = CN()
    cfg.sampler.name = '' # random_identity;sampler
    cfg.sampler.num_instances = 4 # number of instances per identity for RandomIdentitySampler

    # train
    cfg.train = CN()
    cfg.train.optim = 'adam'
    cfg.train.lr = 0.0003
    cfg.train.weight_decay = 5e-4
    cfg.train.weight_decay_bias = 5e-4
    cfg.train.max_epoch = 60
    cfg.train.start_epoch = 0
    cfg.train.batch_size = 32
    cfg.train.staged_lr = False # set different lr to different modules
    cfg.train.new_layers = ['classifier'] # newly added modules with default lr
    cfg.train.base_lr_mult = 0.1 # learning rate multiplier for base modules
    cfg.train.lr_scheduler = 'single_step'
    cfg.train.stepsize = [20] # stepsize to decay learning rate
    cfg.train.warmup_factor = 0.1
    cfg.train.warmup_iters = 10
    cfg.train.freeze_iters = 0
    cfg.train.warmup_method = 'linear'
    cfg.train.gamma = 0.1 # learning rate decay multiplier
    cfg.train.delay_iters = 30
    cfg.train.eta_min_lr = 0.
    cfg.train.print_freq = 50 # print frequency
    cfg.train.seed = 1 # random seed
    cfg.train.opti_open_init = False
    cfg.train.metric = "euclidean" #['euclidean','k-reciprocal','cosine']
    cfg.train.lambda_value = 0.1


    # optimizer
    cfg.train.sgd = CN()
    cfg.train.sgd.momentum = 0.9 # momentum factor
    cfg.train.sgd.dampening = 0. # dampening for momentum
    cfg.train.sgd.nesterov = False # Nesterov momentum
    cfg.train.rmsprop = CN()
    cfg.train.rmsprop.alpha = 0.99 # smoothing constant
    cfg.train.adam = CN()
    cfg.train.adam.beta1 = 0.9 # exponential decay rate for first moment
    cfg.train.adam.beta2 = 0.999 # exponential decay rate for second moment



    # test
    cfg.test = CN()
    cfg.test.batch_size = 100
    cfg.test.dist_metric = 'euclidean' # distance metric, ['euclidean', 'cosine']
    cfg.test.print_freq = 200
    cfg.test.normalize_feature = False # normalize feature vectors before computing distance
    cfg.test.ranks = [1, 5, 10, 20] # cmc ranks
    cfg.test.evaluate = False # test only
    cfg.test.eval_freq = -1 # evaluation frequency (-1 means to only test after training)
    cfg.test.start_eval = 0 # start to evaluate after a specific epoch
    cfg.test.start_save = 0
    cfg.test.rerank = False # use person re-ranking
    cfg.test.lambda_value = 0.3
    cfg.test.visrank = False # visualize ranked results (only available when cfg.test.evaluate=True)
    cfg.test.visrank_topk = 10 # top-k ranks to visualize
    cfg.test.visactmap = False # visualize CNN activation maps
    cfg.test.flip = False #test when sample flip
    cfg.test.use_cython = False
    return cfg
